#!/bin/bash


#
# 请在Windows上使用git bash执行

# 参数配置
python_version="3.12.10"        # 修改版本
python_embed_url="https://www.python.org/ftp/python/$python_version/python-$python_version-embed-amd64.zip"
target_dir="./PythonEmbedded_$python_version"  # 安装目录
pip_libs=("requests")            # 需要安装的库

# 步骤 1：下载并解压
echo "Downloading Python Embedded $python_version..."
rm -rf $target_dir
mkdir -p "$target_dir"
wget "$python_embed_url" -O "$target_dir/python-embedded.zip"
unzip -q "$target_dir/python-embedded.zip" -d "$target_dir"
rm "$target_dir/python-embedded.zip"

# 步骤 2：启用 pip
pth_name=$(echo $python_version | awk -F "." '{printf("%s%s",$1,$2)}')
pth_file="$target_dir/python${pth_name}._pth"
sed -i 's/#import site/import site/g' "$pth_file"

# 步骤 3：安装 pip
echo "Installing pip..."
wget https://bootstrap.pypa.io/get-pip.py -O "$target_dir/get-pip.py"
"$target_dir/python.exe" "$target_dir/get-pip.py"

# 步骤 4：安装第三方库
echo "Installing libraries: ${pip_libs[@]}"
"$target_dir/python.exe" -m pip install "${pip_libs[@]}"

# 输出提示
echo "Python Embedded with pip is ready! Path: $target_dir"
echo "Run manually: export PATH=\"$target_dir:\$PATH\""
